<?php
/**
 * Created by PhpStorm.
 * User: Ellon_Wong
 * Date: 14-5-8
 * Time: 上午12:07
 */

function addRecord_func($arg_body){
    try{

        global $msgArray;
//        $log->info("===================register_func begin=====================");
//        $log->info("传入参数：");
//        $log->info($arg_body);
        if(!array_key_exists("userId",$arg_body)){
            return MsgArray(false,"人员id参数错误",[],"Warn");
        }
        if(!array_key_exists("i_company",$arg_body)){
            return MsgArray(false,"公司参数错误",[],"Warn");
        }

        if(!array_key_exists("i_address",$arg_body)){
            return MsgArray(false,"公司地址参数错误",[],"Warn");
        }

        if(!array_key_exists("i_indate",$arg_body)){
            return MsgArray(false,"入职时间参数错误",[],"Warn");
        }
        if(!array_key_exists("i_outdate",$arg_body)){
            return MsgArray(false,"离职时间参数错误",[],"Warn");
        }
        if(!array_key_exists("i_position",$arg_body)){
            return MsgArray(false,"职位参数错误",[],"Warn");
        }
        if(!array_key_exists("i_award",$arg_body)){
            return MsgArray(false,"获奖参数错误",[],"Warn");
        }



        $rsl = MsgArray(false,"操作失败!",[],"Warn");

        $q_pdo=connectDatabase();

        if(null==$q_pdo){
            return MsgArray(false,"数据库连接异常",[],"Warn");
        }
        $q_pdo->beginTransaction();
        $key = "USER_ID,I_COMPANY,COMPANY_ADDRESS,IN_DATE,OUT_DATE,POSITION,AWARD";
        $sql = "INSERT INTO T_INAUGURATION_RECORD (".$key.") VALUES (?,?,?,?,?,?,?)";

        $stmt = $q_pdo->prepare($sql);
        $num=$stmt->execute(array($arg_body["userId"],$arg_body["i_company"],$arg_body["i_address"],$arg_body["i_indate"],$arg_body["i_outdate"],$arg_body["i_position"],$arg_body["i_award"]));
        if($num<=0){
            return MsgArray(false,"添加就职记录失败！","","Error");
        }
        $q_pdo->commit();
        return MsgArray(true,"添加成功",[],"Success");


    }catch (Exception $e){

        return MsgArray(100001,"系统异常",[],"Error");
    }
}